#include "GameHUD.h"
#include <fstream>
#include <iostream>
#include "../Games/MyGame.h"
#include "../Scene/SceneNode.h"
#include "Ship.h"

GameHUD::GameHUD(int maxFrequency, std::string name) :
		GameEntity(maxFrequency, name) {
	_shipHP = 100;
	this->topLeftCorner.x = this->bottomLeftCorner.x = 7.2f;
	this->topLeftCorner.y = this->topRightCorner.y = -1.0f;
	this->bottomLeftCorner.y = this->bottomRightCorner.y = -5.0f;
	this->bottomRightCorner.x = this->topRightCorner.x = 7.5f;
	this->topLeftCorner.z = this->bottomLeftCorner.z = this->bottomRightCorner.z = this->topRightCorner.z = -15.0f;
	this->borderColor.r = borderColor.g = borderColor.b = 0;
	this->HPtopLeftCorner = this->topLeftCorner;
	this->HPtopRightCorner = this->topRightCorner;
}

GameHUD::~GameHUD() {
}

void GameHUD::reset(){}

int GameHUD::getType() {
	return GAMEHUD;
}

void GameHUD::draw()
{	
	GameEngine::Instance()->getRenderer()->drawRectangle(HPtopLeftCorner,bottomLeftCorner,bottomRightCorner,HPtopRightCorner,getColor(),false);
	GameEngine::Instance()->getRenderer()->drawRectangle(topLeftCorner,bottomLeftCorner,bottomRightCorner,topRightCorner,borderColor,true);
	char highScore[5];
	char score[5];
	itoa(MyGame::Instance()->getHighscore(), highScore,10);
	GameEngine::Instance()->getRenderer()->writeOnScreen("Highscore:", 4, 3.7,14,getColor());
	GameEngine::Instance()->getRenderer()->writeOnScreen(highScore, 4, 3.5, 14,getColor());
	itoa(MyGame::Instance()->getScore(), score,10);
	GameEngine::Instance()->getRenderer()->writeOnScreen("Score:", 4, 3.1, 18,getColor());
	GameEngine::Instance()->getRenderer()->writeOnScreen(score, 4, 2.8, 18,getColor());
	
}

void GameHUD::actualUpdate(unsigned long long timePassed)
{
}

void GameHUD::decHP(int damage) {
	if(_shipHP < 10) {
		MyGame::Instance()->saveScore();
		GameEngine::Instance()->setGameState(MENU);
	}
	else {
		this->_shipHP -= damage;
		HPtopLeftCorner.y -= 0.01*_shipHP;
		HPtopRightCorner.y -= 0.01*_shipHP;
	}
}

int GameHUD::getShipHP() {
	return _shipHP;
}

void GameHUD::setHP(int shipHP) {
	this->_shipHP = shipHP;
	HPtopLeftCorner.y -= 0.01*_shipHP;
	HPtopRightCorner.y -= 0.01*_shipHP;
}
